package com.blb.mapper;

import com.blb.entity.CargoArea;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blb.entity.Ware;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author HuaHao
 * @since 2019-11-16
 */
public interface CargoAreaMapper extends BaseMapper<CargoArea> {

    /* 分页查询 */
    List<Map<String,Object>>  findAllCargoArea(@Param("start") int start, @Param("wareId") String wareId, @Param("length") int length, @Param("goodsName") String goodsName, @Param("deteTime") String deteTime, String companyId);
    int count(@Param("goodsName") String goodsName, @Param("deteTime") String deteTime,@Param("wareId") String wareId);

    /*依据仓库id查询货区信息--zyp*/
    @Select("SELECT  id,goods_no,ware_id,goods_name  FROM t_cargo_area WHERE ware_id = #{wareId}")
    List<CargoArea> findByWareId(String wareId);

    /* 根据公司id查询所有货区信息(模糊查询下拉框) */
    @Select("select * from t_cargo_area where ware_id = #{wareId}")
    List<CargoArea> findAllCarByWareId(CargoArea cargoArea);

    /* 添加货区前去查此仓库现有的货区 */
    @Select("SELECT COUNT(ware_id) FROM t_cargo_area WHERE ware_id = #{id}")
    int countCargoNum(String id);

    /* 添加货区 */
    @Insert("INSERT INTO t_cargo_area(id,goods_no ,goods_name , ware_id , person_id , shelves_num , dete_time1 , area, status , details, company_id) VALUES" +
     " (#{id},#{goodsNo},#{goodsName},#{wareId},#{personId},#{shelvesNum},#{deteTime1},#{area},#{status},#{details},#{companyId})")
    void AddCargoArea(CargoArea cargoArea);

    /* 根据公司id查询所有货区id 找出最大id*/
    @Select("select id from t_cargo_area")
    List<Integer> findAllId();

    /* 修改仓库 */
    @Update("UPDATE t_cargo_area SET goods_no=#{goodsNo},goods_name=#{goodsName},shelves_num=#{shelvesNum} ,details=#{details} where id= #{id}")
    void UpdateCargo(CargoArea cargoArea);

    /* 修改启用状态 */
    @Update("update t_cargo_area set status = '0' where id= #{id}")
    void UpdateWareStatus(CargoArea cargoArea);

    /* 修改停用用状态 */
    @Update("update t_cargo_area set status = '1' where id= #{id}")
    void UpdateWareStatus1(CargoArea cargoArea );
}